<template>
	<view v-show="info">
		<image src="@/static/deleft.png" :style="{ top: sH +10+ 'px' }" mode="widthFix"
			style="width: 40rpx;position: fixed;margin-left: 32rpx;z-index: 999;" @click="back"></image>
		<view class="bag">
			<map id="map_container" :latitude="myla" :longitude="mylo" scale="16" :markers="markers"
				:polyline="polyline" :show-location="true" class="map" :circles="circles">
				<cover-view slot="callout">
					<block v-for="(item,index) in markers" :key="index">
						<cover-view class="customCallout" :marker-id="item.id">
							<cover-view class="content">
								<cover-view style="display: flex;font-size: 24rpx;">	<cover-view>距车辆</cover-view>	<cover-view style="margin: 0 2rpx;font-size: 24rpx;color: #4281FF;">{{info.Destination.km}}</cover-view> <cover-view>km</cover-view> </cover-view>
							</cover-view>
						</cover-view>
					</block>
				</cover-view>
			</map>
			<view class="botinfo">
				<!-- 新订单  拖车/电池/开锁/服务-->
				<view class="infok" v-show="info.rider_status==0">
					<view class="title flex justify-between">
						<view class="t_o items-center flex">
							<span>￥{{info.actual_price}}</span>
						</view>
						<view class="t_w flex" v-show="curNow==2||curNow==1">
							<view class="" style="font-size: 28rpx;color: #333A47;">
								{{info.expected_arrival}}
							</view>
							<view class="" style="font-size: 28rpx;color: #999CA3;margin-left: 8rpx;">
								前送达
							</view>
						</view>
						<view class="" style="font-size: 28rpx;color: #999CA3;" v-show="curNow==0||curNow==3">
							约<span style="font-weight: bold;font-size: 28rpx;color: #333A47;">12</span>km
						</view>

					</view>
					<view class="qu flex items-center">
						<view class="q_o_o  flex-center">
							{{curNow==2?'取':curNow==3?'锁':curNow==1?'服':'车'}}
						</view>
						<view class="q_w">
							{{info.vehicle.trailer_address}}
						</view>
					</view>
					<view class="info flex items-start">
						<view class="o" v-show="curNow==0||curNow==2">
							{{info.vehicle.km}}km
						</view>
						<view class="h" >
							
						</view>
					
					</view>
					<view class="qu flex items-center">
						<view class="q_o_t  flex-center">
							{{curNow==2?'收':'目'}}
						</view>
						<view class="q_w    ">
							{{info.Destination.user_location}}
						</view>
					</view>
					<view class="info flex items-start">
						<view class="o">
							{{info.Destination.km}}km
						</view>
						<view class="t">
							{{info.Destination.consignee}}
						</view>
						<view class="h">
							{{ info.Destination.mobile }}
						</view>
						<view class="f flex-center" v-show="info.is_door==1">
							上门安装
						</view>
					</view>
					<!-- <view class="butgp flex">
				<view class="t_jd flex-center">
					接单
				</view>
			</view> -->
				</view>
				<!-- 待取货-进行中- 拖车/电池/开锁/服务-->
				<view class="infok" v-show="info.rider_status==1||info.rider_status==2">
					<view class="title flex justify-between">
						<view class="t_o items-center flex">
							<span>￥{{info.actual_price}}</span>
						</view>
						<view class="flex" style="color: #333A47;font-size: 28rpx; font-weight: bold;" v-if="info.is_overtime!=0">
							已超时<span style="color: #FF6401;font-size: 28rpx;">{{info.overtime.overtime}}分钟</span>，请尽快配送
						</view>
						<view class="" style="font-weight: bold;font-size: 28rpx;color: #3377FF;" v-else-if="info.rider_status==2">
							服务中
						</view>
					<!-- 	<view class="t_w flex items-end" v-else>
							<view class="" style="font-size: 28rpx;color: #333A47;margin:0 8rpx;">
								{{info.expected_arrival}}
							</view>
							<view class="" style="font-size: 28rpx;color: #999CA3;">
								前送达
							</view>
						</view> -->
					</view>
					<view class="qu flex items-center">
						<view class="  flex-center" :class="curNow==1?'q_o_b':'q_o_o'" v-show="curNow==1||curNow==2">
							{{curNow==2?'取':curNow==3?'锁':curNow==1?'服':''}}
						</view>
						<view class="q_o_d  flex-center" v-show="curNow==3">
							{{curNow==2?'取':curNow==3?'锁':''}}
						</view>
						<view class="q_w    ">
							{{info.vehicle.trailer_address}}
						</view>
					</view>
					<!-- <view class="info flex items-start" v-show="curNow==0||curNow==2">
						<view class="o">
							{{info.Destination.km}}km
						</view>
						<view class="h" v-show="curNow!=0">
							{{info.Destination.user_location}}
						</view>
					</view> -->
					<view class="qu flex items-center">
						
						<view class="q_o_o flex-center">
							目
						</view>
						<!-- 拖车 已经到达车辆位置-->
						<view class="q_w    ">
							{{info.Destination.user_location}}
						</view>
					</view>
					<view class="info flex items-start">
						<view class="o">
							{{info.Destination.km}}km
						</view>
						<view class="t">
							{{info.Destination.consignee}}
						</view>
						<view class="h">
							{{ info.Destination.mobile }}
						</view>
						<view class="f flex-center" v-show="info.is_door==1">
							上门安装
						</view>
					</view>
				</view>

				<!-- 现场照片 -->
				<view class="xcimg">
					<view class="title">
						描述照片
					</view>
					<view class="" style="font-size: 28rpx;color: #00091A;margin: 24rpx 24rpx 24rpx 0;">
						{{info.on_site_content}}
					</view>
					<view class="imglist flex justify-start flex-wrap">
						<image :src="i" mode="widthFix" class="zwt" v-for="i in info.on_site_photos"></image>
					</view>
				</view>
				<!-- 拖车  信息 -->
				<view class="gzinfo">
					<view class="t flex justify-between">
						<view class="gz_o">
							服务类型
						</view>
						<view class="gz_t">
							{{info.servicetype}}
						</view>
					</view>
					<view class="t flex justify-between">
						<view class="gz_o">
							是否加急
						</view>
						<view class="gz_t">
							{{info.service_j==1?'是':'否'}}
						</view>
					</view>
					<view class="t flex justify-between">
						<view class="gz_o">
							下单时间
						</view>
						<view class="gz_t">
							{{info.time.createtime}}
						</view>
					</view>
					<view class="t flex justify-between" v-show="info.rider_status==1||info.rider_status==2">
						<view class="gz_o">
							接单时间
						</view>
						<view class="gz_t">
							{{info.time.order_acceptance_time}}
						</view>
					</view>
					<view class="t flex justify-between" v-show="info.rider_status==2">
						<view class="gz_o">
							到达目的地时间
						</view>
						<view class="gz_t">
							{{info.time.arrival_time_at_destination}}
						</view>
					</view>
					<view class="t flex justify-between"@click="qrsds(-1,info.specifications)" v-if="info.order_schedule==0&&info.servicetype_id==1" >
						<view class="gz_o">
							导航到商家
						</view>
						<view class="gz_t">
							点击导航>
						</view>
					</view>
					<view class="t flex justify-between"@click="qrsds(info.order_schedule,info.Destination)" v-if="info.order_schedule==1&&info.servicetype_id==1" >
						<view class="gz_o">
							导航到用户
						</view>
						<view class="gz_t">
							点击导航>
						</view>
					</view>
					<view class="t flex justify-between"@click="qrsds(1,info.Destination)" v-if="info.order_schedule==0&&info.servicetype_id!=1" >
						<view class="gz_o">
							导航到用户
						</view>
						<view class="gz_t">
							点击导航>
						</view>
					</view>
				</view>
				<view class="butgp flex" v-show="info.rider_status==0" @click="service_orders">
					<view class="t_jd flex-center">
						接单
					</view>
				</view>
				<view class="butgp flex justify-between" v-show="info.rider_status==1">
					<view class="o flex-center" @click="bdph(info.Destination.mobile)">
						<image src="@/static/phone.png" mode="widthFix" style="width: 32rpx;margin-right: 8rpx;">
						</image>
						<view class="">
							客户
						</view>
					</view>
				    
					<!-- <view class="t flex-center" @click="qrsd(info.rider_status)" >
						确认到达
					</view> -->
					<!-- <view class="t flex-center" @click="qrsds(info.order_schedule,info.specifications)" v-if="info.order_schedule==0" >
						导航到商家
					</view> -->
				
					<view class="t flex-center" @click="qrsds(info.order_schedule,info.specifications)" v-if="info.order_schedule==0&&info.servicetype_id==1" >
					     已取到货，正在派送
					</view>
					<view class="t flex-center" @click="qrsd(info.rider_status)" v-if="info.order_schedule==1&&info.servicetype_id==1" >
					    确认到达
					</view>
					<view class="t flex-center" @click="qrsd(info.rider_status)" v-if="info.order_schedule==0&&info.servicetype_id!=1" >
					    确认到达
					</view>
				</view>
				<view class="butgp flex justify-between" v-show="info.rider_status==2">
					<view class="o flex-center" @click="bdph(info.Destination.mobile)">
						<image src="@/static/phone.png" mode="widthFix" style="width: 32rpx;margin-right: 8rpx;">
						</image>
						<view class="">
							客户
						</view>
					</view>
					<view class="t flex-center" @click="qrsd(info.rider_status)">
						服务完成
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import amap from "@/amap-wx.130.js";
	export default {
		data() {
			return {
				info:'',
				curNow: 0,
				active: 0,
				sH: '',
				key: "1736dd18a297e467c119fb19bd9bb0c7",
				amapPlugin: null,
				latitude: 35.408925,
				longitude: 116.596165,
				mapInfo: [],
				markers: [],
				circles: [

				],
				distance: "",
				cost: "",
				polyline: [],
				mylo: '',
				myla: '',
				type:'',
				id:''
			};
		},
		onLoad(o) {
			this.getWinTop().then(res => {
				this.sH = res.statusBar;
			});
			console.log(o);
			this.curNow = o.curNow
			this.active = o.active
			this.type=o.type
			this.id=o.id


			this.amapPlugin = new amap.AMapWX({
				key: this.key //该key 是在高德中申请的微信小程序key
			});
			this.cshLo()
		},
		methods: {
			bdph(phoneNumber) {
				uni.makePhoneCall({
					phoneNumber
				});
			
			},
			back() {
				uni.navigateBack()
			},
			service_order(){
				this.$api.service_order({
					order_id:this.id,
					lat:this.myla,
					lng:this.mylo
				}).then(res=>{
					this.info=res.data
					
					this.loac()
				})
			},
			
			service_orders(){
				this.$api.service_orders({
					order_id:this.id
				}).then(res=>{
					this.cshLo()
				})
			},
			qrsd(status){
				let app=this
				if(status==1){
					this.$api.service_destination({
					order_id:this.id,
				}).then(res=>{
					app.service_order()
					// uni.navigateBack()
				})
				}else{
					this.$api.service_completed({
						order_id:this.id,
					}).then(res=>{
						uni.redirectTo({
							url:'/pages/Alldetail_f/complete?id='+this.id
						})
					})
				}
				
			},
			qrsds(status,i){
				if(status==-1){
					uni.openLocation({
						latitude: parseFloat(i.lat),
						longitude: parseFloat(i.lng),
						scale: 18
					});
				}
				if(status==0){
					let app=this
					this.$api.qrsds({
						order_id:this.id,
					}).then(res=>{
						app.service_order()
						// uni.navigateBack()
					})
				}
				if(status==1){
					uni.openLocation({
						latitude: parseFloat(i.user_latitude),
						longitude: parseFloat(i.user_longitude),
						scale: 18
					});
				}
				// let app=this
				// // if(status==1){
				// 	this.$api.qrsds({
				// 	order_id:this.id,
				// }).then(res=>{
				// 	app.service_order()
				// 	// uni.navigateBack()
				// })
				// }else{
				// 	this.$api.service_completed({
				// 		order_id:this.id,
				// 	}).then(res=>{
				// 		uni.navigateTo({
				// 			url:'/pages/Alldetail_f/complete?id='+this.id
				// 		})
				// 	})
				// }
				
			},
			cshLo() {
				let app=this
				uni.getLocation({
					type: 'wgs84',
					success: function(res) {
						console.log('当前位置的经度：' + res.longitude);
						app.myla = res.latitude
						app.mylo = res.longitude
						console.log('当前位置的纬度：' + res.latitude);
						app.service_order()
					},
					fail(err) {
						console.log(err, 'err');
					}
				});
				
				
			},
			loac(){
				let self = this;
				console.log(this.info,'this.info.vehicle');
				let a=this.mylo+','+this.myla
				let b=this.info.Destination.user_longitude+','+this.info.Destination.user_latitude
				console.log(a,b);
				this.amapPlugin.getDrivingRoute({
									origin:a,
									destination:b,
									success: (data) => {
										console.log(data.paths[0].steps, 'aaa');
										const points = data.paths[0].steps.map(step => {
											return step.polyline.split(';').map(coord => {
												const [longitude, latitude] = coord.split(',');
												return {
													longitude: parseFloat(longitude),
													latitude: parseFloat(latitude)
												};
											});
										}).flat();
										// 获取第一个和最后一个经纬度点
										const firstPoint = points[0];
										const lastPoint = points[points.length - 1];
										// 更新circles数组
										this.circles = [
											// 起点圆
											{
												latitude: firstPoint.latitude,
												longitude: firstPoint.longitude,
												color: '#3377FF',
												fillColor: '#ffffff',
												radius: 1,
												strokeWidth: 2
											},
											// 终点圆
											{
												latitude: lastPoint.latitude,
												longitude: lastPoint.longitude,
												color: '#3377FF',
												fillColor: '#ffffff',
												radius: 1,
												strokeWidth: 2
											}
										];
										let app = this
										
										// 更新markers数组
										this.markers = [
											// 起点标记
											
											// 终点标记
											{
												id: 1,
												width: 24,
												height: 35,
												latitude: lastPoint.latitude,
												longitude: lastPoint.longitude,
												iconPath: '/static/mdd2.png', // 自定义终点图标路径
												title: '终点'
											},
											{
												id: 2,
												width: 34,
												height: 34,
												latitude: this.latitude,
												longitude: this.longitude,
												iconPath: '/static/my (2).png', // 自定义终点图标路径
												title: '11',
												customCallout: {
													anchorY: 0,
													anchorX: 0,
													display: "ALWAYS"
												}
											}
										];
										// 更新polyline数组
										this.polyline = [{
											points: points,
											color: "#3377FF",
											width: 7,
											dottedLine: false
										}];
										console.log('this.circles', this.circles);
									},
									fail: (info) => {
										console.log(info, 'bbb');
									}
								});
			}
		},

	}
</script>

<style lang="scss">
	::v-deep .amap-logo {
		opacity: 0 !important;
	}

	::v-deep .amap-copyright {
		opacity: 0 !important;
	}


	.bag {
		.map {
			height: 916rpx;
			width: 100%;

			.customCallout {
				padding: 8rpx 24rpx;
				width: 190rpx;
				height: 56rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 0rpx 24rpx 0rpx rgba(0, 0, 0, 0.25);
				border-radius: 32rpx 32rpx 32rpx 32rpx;
				display: inline-flex;
				justify-content: center;
				align-items: center;
			}

			.content {
				flex: 0 1 auto;
				font-size: 24rpx;
				color: #00091A;
			}

			span {
				font-size: 24rpx;
				color: #4281FF;
			}
		}

		.botinfo {
			margin: -70rpx auto;
			padding-bottom: 100rpx;
			position: absolute;
			top: 92%;
			left: 50%;
			transform: translate(-50%, -50%);

			.infok {
				margin: 0 auto;
				z-index: 1;
				padding: 24rpx;
				width: 686rpx;
				// height: 436rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 4rpx 16rpx 0rpx rgba(51, 119, 255, 0.05);
				border-radius: 24rpx 24rpx 24rpx 24rpx;

				.title {
					.t_o {
						font-weight: bold;
						font-size: 36rpx;
						color: #FF6401;

						.ji {
							color: #FFFFFF;
							font-size: 24rpx;
							width: 40rpx;
							height: 40rpx;
							background: #FF6401;
							border-radius: 8rpx 8rpx 8rpx 8rpx;
						}
					}

					.t_w {
						font-weight: bold;
						font-size: 28rpx;
						color: #3377FF;
					}
				}

				.qu {
					margin-top: 30rpx;
					padding-left: 10rpx;

					.q_o {
						width: 40rpx;
						height: 40rpx;
						background: #F7FAFF;
						border-radius: 16rpx 16rpx 16rpx 16rpx;
						font-size: 20rpx;
						color: #3377FF;
					}

					.q_o_o {
						width: 40rpx;
						height: 40rpx;
						background: #3377FF;
						border-radius: 16rpx 16rpx 16rpx 16rpx;
						font-size: 20rpx;
						color: #FFFFFF;
					}

					.q_o_b {
						width: 40rpx;
						height: 40rpx;
						background: #F7FAFF;
						border-radius: 16rpx 16rpx 16rpx 16rpx;
						font-size: 20rpx;
						color: #3377FF;
					}

					.q_o_w {
						width: 40rpx;
						height: 40rpx;
						background: #F7FAFF;
						border-radius: 16rpx 16rpx 16rpx 16rpx;
						font-size: 20rpx;
						color: #3377FF;
					}

					.q_w {
						padding-left: 42rpx;
						font-weight: bold;
						font-size: 32rpx;
						color: #00091A;
						width: 558rpx;
					}

					.q_o_t {
						width: 40rpx;
						height: 40rpx;
						background: #3377FF;
						border-radius: 16rpx 16rpx 16rpx 16rpx;
						font-size: 20rpx;
						color: #FFFFFF;
					}

					.q_o_d {
						width: 40rpx;
						height: 40rpx;
						background: #F7FAFF;
						border-radius: 16rpx 16rpx 16rpx 16rpx;
						font-size: 20rpx;
						color: #3377FF;
					}
				}

				.info {
					margin-top: 15rpx;

					.o {
						font-size: 20rpx;
						color: #999CA3;
					}

					.t {
						font-weight: bold;
						margin-left: 35rpx;
						font-size: 28rpx;
						color: #333A47;
					}

					.h {
						margin-left: 35rpx;
						font-size: 28rpx;
						color: #999CA3;
					}

					.f {
						margin-left: 24rpx;
						width: 112rpx;
						height: 48rpx;
						background: #3377FF;
						border-radius: 8rpx 8rpx 8rpx 8rpx;
						font-size: 24rpx;
						color: #FFFFFF;
					}
				}

				// .butgp {
				// 	margin-top: 30rpx;

				// 	.t_w {
				// 		width: 160rpx;
				// 		height: 68rpx;
				// 		border-radius: 8rpx 8rpx 8rpx 8rpx;
				// 		border: 2rpx solid #CCCED1;
				// 		font-size: 28rpx;
				// 		color: #666B75;
				// 	}

				// 	.t_w_h {
				// 		width: 160rpx;
				// 		height: 68rpx;
				// 		background: #3377FF;
				// 		border-radius: 8rpx 8rpx 8rpx 8rpx;
				// 		color: #ffffff;
				// 		margin-left: 24rpx;
				// 	}

				// 	.o {
				// 		width: 230rpx;
				// 		height: 100rpx;
				// 		background: #F7F7F7;
				// 		border-radius: 16rpx 16rpx 16rpx 16rpx;
				// 		font-size: 32rpx;
				// 		color: #333A47;
				// 	}

				// 	.t {
				// 		margin-left: 24rpx;
				// 		width: 384rpx;
				// 		height: 100rpx;
				// 		background: #3377FF;
				// 		box-shadow: 0rpx 4rpx 16rpx 0rpx rgba(51, 119, 255, 0.05);
				// 		border-radius: 16rpx 16rpx 16rpx 16rpx;
				// 		font-size: 32rpx;
				// 		color: #FFFFFF;
				// 	}

				// 	.t_jd {
				// 		width: 638rpx;
				// 		height: 100rpx;
				// 		background: #3377FF;
				// 		box-shadow: 0rpx 4rpx 16rpx 0rpx rgba(51, 119, 255, 0.05);
				// 		border-radius: 16rpx 16rpx 16rpx 16rpx;
				// 		color: #FFFFFF;
				// 	}
				// }
			}

			.xcimg {
				margin: 24rpx auto 0 auto;
				width: 686rpx;
				// height: 272rpx;
				padding: 32rpx 24rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 4rpx 16rpx 0rpx rgba(51, 119, 255, 0.05);
				border-radius: 24rpx 24rpx 24rpx 24rpx;

				.title {
					font-size: 28rpx;
					color: #333A47;
				}

				.imglist {
					.zwt {
						margin-right: 20rpx;
						margin-top: 32rpx;
						width: 140rpx;
						height: 140rpx;
						border-radius: 16rpx 16rpx 16rpx 16rpx;
					}
				}
			}

			.gzinfo {
				padding: 5rpx 24rpx 24rpx;
				margin: 24rpx auto 0 auto;
				width: 686rpx;
				background: #FFFFFF;
				box-shadow: 0rpx 4rpx 16rpx 0rpx rgba(51, 119, 255, 0.05);
				border-radius: 24rpx 24rpx 24rpx 24rpx;

				.t {
					margin-top: 32rpx;
				}

				.gz_o {
					font-size: 28rpx;
					color: #333A47;
				}

				.gz_t {
					font-size: 28rpx;
					color: #00091A;
				}
			}

			.butgp {
				margin: 24rpx auto 0 auto;

				.t_w {
					width: 160rpx;
					height: 68rpx;
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					border: 2rpx solid #CCCED1;
					font-size: 28rpx;
					color: #666B75;
				}

				.t_w_h {
					width: 160rpx;
					height: 68rpx;
					background: #3377FF;
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					color: #ffffff;
					margin-left: 24rpx;
				}

				.o {
					width: 230rpx;
					height: 100rpx;
					background: #F7F7F7;
					border-radius: 16rpx 16rpx 16rpx 16rpx;
					font-size: 32rpx;
					color: #333A47;
				}

				.t {
					margin-left: 24rpx;
					width: 384rpx;
					height: 100rpx;
					background: #3377FF;
					box-shadow: 0rpx 4rpx 16rpx 0rpx rgba(51, 119, 255, 0.05);
					border-radius: 16rpx 16rpx 16rpx 16rpx;
					font-size: 32rpx;
					color: #FFFFFF;
				}

				.t_jd {
					width: 100%;
					height: 100rpx;
					background: #3377FF;
					box-shadow: 0rpx 4rpx 16rpx 0rpx rgba(51, 119, 255, 0.05);
					border-radius: 16rpx 16rpx 16rpx 16rpx;
					color: #FFFFFF;
					margin: 0 auto;
				}
			}
		}
	}
</style>